<?xml version="1.0" encoding="utf-8" ?>

<xsl:stylesheet
   version="2.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:fn="http://www.w3.org/2005/xpath-functions"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
   xmlns:owl="http://www.w3.org/2002/07/owl#"
   xmlns:xsd="http://www.w3.org/2001/XMLSchema"
   xmlns:dcterms="http://purl.org/dc/terms/"
   xmlns:dcmiype="http://purl.org/dc/dcmitype/"
   xmlns:bibo="http://purl.org/ontology/bibo/"
   xmlns:foaf="http://xmlns.com/foaf/0.1/"
   xmlns:bio="http://purl.org/vocab/bio/0.1/"
   xmlns:skos="http://www.w3.org/2004/02/skos/core#"
   xmlns:wgs84_pos="http://www.w3.org/2003/01/geo/wgs84_pos#"
   xmlns:ore="http://www.openarchives.org/ore/terms/"
   xmlns:lvont="http://lexvo.org/ontology#"
   xmlns:lode = "http://linkedevents.org/ontology/"
   xmlns:event="http://purl.org/NET/c4dm/event.owl#"
   xmlns:time = "http://www.w3.org/2006/time#"
   xmlns:timeline="http://purl.org/NET/c4dm/timeline.owl#"
   xmlns:arch="http://purl.org/archival/vocab/arch#"
   xmlns:crm="http://erlangen-crm.org/current/"
   xmlns:locah="http://data.archiveshub.ac.uk/def/"

>

<!--
Created by Pete Johnston, Eduserv for the SALDA project, 2011

Adapted from the XSLT http://data.archiveshub.ac.uk/xslt/20110502/ead2rdf.xsl
created by Pete Johnston, Eduserv for the LOCAH project, 2010-2011

Copyright (c) 2011, Eduserv
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of Eduserv nor the
      names of its contributors may be used to endorse or promote products
      derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL EDUSERV BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->

<!--

lookup-ead2rdf.xsl

Extends base-ead2rdf.xsl to perform keyword/name lookups.

Requires three parameters:
    root = "base" URI for generating "thing URIs" 
    e.g. root=http://example.org 
    results in URIs like http://example.org/id/archivalresource/gb123abc
    
    authnames = URI of personal names list (XML)
    
    keywords = URI of keywords list (XML)

-->

<xsl:import href="base-ead2rdf.xsl" />

<xsl:param name="authnames" />
<xsl:param name="keywords" />

<xsl:template match="document-node()">
        <xsl:message>Transforming document: <xsl:value-of select="document-uri(.)" /></xsl:message>
	<xsl:comment>Input document: <xsl:value-of select="document-uri(.)" /></xsl:comment>
	<xsl:comment>XSLT transform: <xsl:value-of select="static-base-uri()" /></xsl:comment>
	<xsl:comment>Time of transform: <xsl:value-of select="current-dateTime()" /></xsl:comment>
	<xsl:comment>Authnames: <xsl:value-of select="$authnames" /></xsl:comment>
	<xsl:comment>Keywords: <xsl:value-of select="$keywords" /></xsl:comment>

	<xsl:apply-templates />
</xsl:template>


<xsl:template name="extend-uod-desc">
<xsl:param name="thing" />

	<xsl:call-template name="match-personal-name">
		<xsl:with-param name="thing" select="$thing" />
		<xsl:with-param name="label" select="normalize-space(did/unittitle)" />
	</xsl:call-template>
		
	<xsl:call-template name="match-concept-keyword">
		<xsl:with-param name="thing" select="$thing" />
		<xsl:with-param name="label" select="normalize-space(did/unittitle)" />
	</xsl:call-template>

</xsl:template>



<xsl:template name="match-personal-name">
<xsl:param name="thing" />
<xsl:param name="label" />


	<xsl:variable name="title" select="normalize-space(did/unittitle)" />
	<xsl:variable name="scope" select="normalize-space(scopecontent)" />

	<xsl:for-each select="document($authnames)/nra/entry">

		<xsl:variable name="personEntry">
			<xsl:call-template name="test-keyword">
				<xsl:with-param name="entry" select="." />
				<xsl:with-param name="i" select="1" />
				<xsl:with-param name="title" select="$title" />
				<xsl:with-param name="scope" select="$scope" />
			</xsl:call-template>
		</xsl:variable>
	
		<xsl:if test="not($personEntry = '')">
		
			<xsl:variable name="personLabel" select="$personEntry/entry/name" /> 
		
			<xsl:comment>SALDA Persname = <xsl:value-of select="$personLabel" /></xsl:comment>
			<xsl:variable name="slug">
				<xsl:call-template name="slugify">
					<xsl:with-param name="text" select="$personLabel" />
				</xsl:call-template>
			</xsl:variable>
	
			<xsl:variable name="concept" select="concat($id, 'concept/person/nra/', $slug)" />
			<xsl:variable name="person" select="concat($id, 'person/nra/', $slug)" />
	
			<xsl:element name="locah:associatedWith">
				<xsl:comment>About the Concept (Person)</xsl:comment> 
				<xsl:element name="skos:Concept">
					<xsl:attribute name="rdf:about"><xsl:value-of select="$concept" /></xsl:attribute>
		
					<xsl:element name="rdfs:label"><xsl:attribute name="xml:lang" select="'en'" /><xsl:value-of select="$personLabel"/></xsl:element>
					<xsl:element name="skos:prefLabel"><xsl:attribute name="xml:lang" select="'en'" /><xsl:value-of select="$personLabel"/></xsl:element>
					
					<xsl:element name="skos:inScheme">
						<xsl:element name="skos:ConceptScheme">
							<xsl:attribute name="rdf:about"><xsl:value-of select="concat($id, 'conceptscheme/nra')"/></xsl:attribute>
							<xsl:element name="rdfs:label"><xsl:attribute name="xml:lang" select="'en'" /><xsl:value-of select="'NRA'"/></xsl:element>
						</xsl:element>
					</xsl:element>
		
					<xsl:element name="foaf:focus">
						<xsl:comment>About the Person</xsl:comment> 
						<xsl:element name="foaf:Person">	
							<xsl:attribute name="rdf:about"><xsl:value-of select="$person" /></xsl:attribute>
							<xsl:element name="rdf:type">
								<xsl:attribute name="rdf:resource"><xsl:value-of select="concat($foaf, 'Agent')" /></xsl:attribute>
							</xsl:element>
							<xsl:element name="rdf:type">
								<xsl:attribute name="rdf:resource"><xsl:value-of select="concat($dcterms, 'Agent')" /></xsl:attribute>
							</xsl:element>
							<xsl:element name="rdf:type">
								<xsl:attribute name="rdf:resource"><xsl:value-of select="concat($crm, 'E21_Person')" /></xsl:attribute>
							</xsl:element>
							<xsl:element name="rdfs:label"><xsl:attribute name="xml:lang" select="'en'" /><xsl:value-of select="$personLabel"/></xsl:element>
							
							<xsl:choose>
								<xsl:when test="not($personEntry/entry/surname = '') and not($personEntry/entry/forenames = '')" >  
									<xsl:element name="foaf:name">
										<xsl:for-each select="$personEntry/entry/forenames">
											<xsl:value-of select="concat(normalize-space(.), ' ')" />
										</xsl:for-each>
										<xsl:value-of select="$personEntry/entry/surname"/>
									</xsl:element>
									<xsl:element name="foaf:familyName"><xsl:value-of select="$personEntry/entry/surname"/></xsl:element>
									<xsl:element name="foaf:givenName"><xsl:value-of select="$personEntry/entry/forenames"/></xsl:element>
								</xsl:when>
								<xsl:otherwise>
								</xsl:otherwise>
							</xsl:choose>
							
							<xsl:if test="not($personEntry/entry/dates ='')">
								<xsl:element name="locah:dates"><xsl:value-of select="$personEntry/entry/dates"/></xsl:element>
							
								<xsl:call-template name="make-life-events">
									<xsl:with-param name="person" select="$person" />
									<xsl:with-param name="label" select="$personLabel" />
									<xsl:with-param name="indates" select="$personEntry/entry/dates" />
								</xsl:call-template>

							</xsl:if>

							<xsl:if test="not($personEntry/entry/title ='')">
								<xsl:element name="locah:title"><xsl:value-of select="$personEntry/entry/title"/></xsl:element>
							</xsl:if>

							<xsl:if test="not($personEntry/entry/epithet ='')">
								<xsl:element name="locah:epithet"><xsl:value-of select="$personEntry/entry/epithet"/></xsl:element>
							</xsl:if>

							<xsl:for-each select="$personEntry/entry/sameas">
								<xsl:element name="owl:sameAs">
									<xsl:attribute name="rdf:resource" select="." />
								</xsl:element>
							</xsl:for-each>

						</xsl:element>
					</xsl:element>
				</xsl:element>
			</xsl:element>
		</xsl:if>
	
	</xsl:for-each>
	
</xsl:template>

<xsl:template name="test-keyword">
<xsl:param name="entry" />
<xsl:param name="i" />
<xsl:param name="title" />
<xsl:param name="scope" />

	<xsl:if test="$i &lt;= count($entry/keyword)">
	
		<xsl:variable name="matched">
			<xsl:choose>
				<xsl:when test="matches($title, concat('(^|^(.*)\W)', $entry/keyword[$i], '($|\W(.*)$)'))">
				
<!--					<xsl:message>Title match!</xsl:message> -->
					<xsl:variable name="matched-not">
						<xsl:for-each select="$entry/not">
							<xsl:if test="matches($title, concat('(^|^(.*)\W)', ., '($|\W(.*)$)'))" >
								<xsl:value-of select="."/>
								<xsl:message>Title match CANCELLED! <xsl:value-of select="."/></xsl:message>
							</xsl:if>
						</xsl:for-each>
					</xsl:variable>
					<xsl:if test="$matched-not = ''">
						<xsl:copy-of select="$entry" />
					</xsl:if>
<!--					<xsl:copy-of select="$entry" /> -->
				</xsl:when>
				<xsl:when test="matches($scope, concat('(^|^(.*)\W)', $entry/keyword[$i], '($|\W(.*)$)'))"> 
<!--					<xsl:message>Scope match!</xsl:message> -->
					<xsl:variable name="matched-not">
						<xsl:for-each select="$entry/not">
							<xsl:if test="matches($scope, concat('(^|^(.*)\W)', ., '($|\W(.*)$)'))" >
								<xsl:value-of select="."/>
								<xsl:message>Scope match CANCELLED! <xsl:value-of select="."/></xsl:message>
							</xsl:if>
						</xsl:for-each>
					</xsl:variable>
					<xsl:if test="$matched-not = ''">
						<xsl:copy-of select="$entry" />
					</xsl:if>
<!--					<xsl:copy-of select="$entry" /> -->
				</xsl:when>
				<xsl:otherwise>
					<xsl:call-template name="test-keyword">
						<xsl:with-param name="entry" select="$entry" />
						<xsl:with-param name="i" select="$i + 1" />
						<xsl:with-param name="title" select="$title" />
						<xsl:with-param name="scope" select="$scope" />
					</xsl:call-template>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		
		<xsl:copy-of select="$matched" />
		
	</xsl:if>

</xsl:template>

<xsl:template name="match-concept-keyword">
<xsl:param name="thing" />
<xsl:param name="label" />

	<xsl:variable name="title" select="normalize-space(did/unittitle)" />
	<xsl:variable name="scope" select="normalize-space(scopecontent)" />

<!--	
	<xsl:message>
		<xsl:value-of select="concat('Keyword matching title ', $title)" />
	</xsl:message>
	
	<xsl:message>
		<xsl:value-of select="concat('Keyword matching scope ', $scope)" />
	</xsl:message>
-->

	<xsl:for-each select="document($keywords)/keywords/entry[type='Concept']">

		<xsl:variable name="entry">
			<xsl:call-template name="test-keyword">
				<xsl:with-param name="entry" select="." />
				<xsl:with-param name="i" select="1" />
				<xsl:with-param name="title" select="$title" />
				<xsl:with-param name="scope" select="$scope" />
			</xsl:call-template>
		</xsl:variable>

		<xsl:if test="not($entry = '')">
		
			<xsl:variable name="conceptLabel" select="$entry/entry/label" /> 

			<xsl:comment>SALDA Keyword Concept = <xsl:value-of select="$conceptLabel" /></xsl:comment>
			<xsl:variable name="slug">
				<xsl:call-template name="slugify">
					<xsl:with-param name="text" select="$conceptLabel" />
				</xsl:call-template>
			</xsl:variable>
	
			<xsl:variable name="concept" select="concat($id, 'concept/moa/', $slug)" />
	
			<xsl:element name="locah:associatedWith">
				<xsl:comment>About the Concept</xsl:comment> 
				<xsl:element name="skos:Concept">
					<xsl:attribute name="rdf:about"><xsl:value-of select="$concept" /></xsl:attribute>
		
					<xsl:element name="rdfs:label"><xsl:attribute name="xml:lang" select="'en'" /><xsl:value-of select="$conceptLabel"/></xsl:element>
					<xsl:element name="skos:prefLabel"><xsl:attribute name="xml:lang" select="'en'" /><xsl:value-of select="$conceptLabel"/></xsl:element>
					
					<xsl:element name="skos:inScheme">
						<xsl:element name="skos:ConceptScheme">
							<xsl:attribute name="rdf:about"><xsl:value-of select="concat($id, 'conceptscheme/moa')"/></xsl:attribute>
							<xsl:element name="rdfs:label"><xsl:attribute name="xml:lang" select="'en'" /><xsl:value-of select="'MOA'"/></xsl:element>
						</xsl:element>
					</xsl:element>
					
					<xsl:for-each select="$entry/entry/exactmatch">
						<xsl:element name="skos:exactMatch">
							<xsl:attribute name="rdf:resource" select="." />
						</xsl:element>
					</xsl:for-each>
					<xsl:for-each select="$entry/entry/closematch">
						<xsl:element name="skos:closeMatch">
							<xsl:attribute name="rdf:resource" select="." />
						</xsl:element>
					</xsl:for-each>
					<xsl:for-each select="$entry/entry/broadmatch">
						<xsl:element name="skos:broadMatch">
							<xsl:attribute name="rdf:resource" select="." />
						</xsl:element>
					</xsl:for-each>
					<xsl:for-each select="$entry/entry/narrowmatch">
						<xsl:element name="skos:narrowMatch">
							<xsl:attribute name="rdf:resource" select="." />
						</xsl:element>
					</xsl:for-each>
					<xsl:for-each select="$entry/entry/focus">
						<xsl:element name="foaf:focus">
							<xsl:attribute name="rdf:resource" select="." />
						</xsl:element>
					</xsl:for-each>
				</xsl:element>
			</xsl:element>
		</xsl:if>

	</xsl:for-each>

	<xsl:for-each select="document($keywords)/keywords/entry[type='Genre']">

		<xsl:variable name="entry">
			<xsl:call-template name="test-keyword">
				<xsl:with-param name="entry" select="." />
				<xsl:with-param name="i" select="1" />
				<xsl:with-param name="title" select="$title" />
				<xsl:with-param name="scope" select="$scope" />
			</xsl:call-template>
		</xsl:variable>

		<xsl:if test="not($entry = '')">
		
			<xsl:variable name="conceptLabel" select="$entry/entry/label" /> 

			<xsl:comment>SALDA Keyword Genre = <xsl:value-of select="$conceptLabel" /></xsl:comment>
			<xsl:variable name="slug">
				<xsl:call-template name="slugify">
					<xsl:with-param name="text" select="$conceptLabel" />
				</xsl:call-template>
			</xsl:variable>
	
			<xsl:variable name="concept" select="concat($id, 'concept/moa/', $slug)" />
	
			<xsl:element name="locah:associatedWith">
				<xsl:comment>About the Genre</xsl:comment> 
				<xsl:element name="skos:Concept">
					<xsl:attribute name="rdf:about"><xsl:value-of select="$concept" /></xsl:attribute>

					<xsl:element name="rdf:type">
						<xsl:attribute name="rdf:resource"><xsl:value-of select="concat($locah, 'GenreForm')"/></xsl:attribute>
					</xsl:element>

					
					<xsl:element name="rdfs:label"><xsl:attribute name="xml:lang" select="'en'" /><xsl:value-of select="$conceptLabel"/></xsl:element>
					<xsl:element name="skos:prefLabel"><xsl:attribute name="xml:lang" select="'en'" /><xsl:value-of select="$conceptLabel"/></xsl:element>
					
					<xsl:element name="skos:inScheme">
						<xsl:element name="skos:ConceptScheme">
							<xsl:attribute name="rdf:about"><xsl:value-of select="concat($id, 'conceptscheme/moa')"/></xsl:attribute>
							<xsl:element name="rdfs:label"><xsl:attribute name="xml:lang" select="'en'" /><xsl:value-of select="'MOA'"/></xsl:element>
						</xsl:element>
					</xsl:element>
					
					<xsl:for-each select="$entry/entry/exactmatch">
						<xsl:element name="skos:exactMatch">
							<xsl:attribute name="rdf:resource" select="." />
						</xsl:element>
					</xsl:for-each>
					<xsl:for-each select="$entry/entry/closematch">
						<xsl:element name="skos:closeMatch">
							<xsl:attribute name="rdf:resource" select="." />
						</xsl:element>
					</xsl:for-each>
					<xsl:for-each select="$entry/entry/broadmatch">
						<xsl:element name="skos:broadMatch">
							<xsl:attribute name="rdf:resource" select="." />
						</xsl:element>
					</xsl:for-each>
					<xsl:for-each select="$entry/entry/narrowmatch">
						<xsl:element name="skos:narrowMatch">
							<xsl:attribute name="rdf:resource" select="." />
						</xsl:element>
					</xsl:for-each>
					<xsl:for-each select="$entry/entry/focus">
						<xsl:element name="foaf:focus">
							<xsl:attribute name="rdf:resource" select="." />
						</xsl:element>
					</xsl:for-each>
				</xsl:element>
			</xsl:element>
		</xsl:if>

	</xsl:for-each>

	<xsl:for-each select="document($keywords)/keywords/entry[type='Organization']">

		<xsl:variable name="entry">
			<xsl:call-template name="test-keyword">
				<xsl:with-param name="entry" select="." />
				<xsl:with-param name="i" select="1" />
				<xsl:with-param name="title" select="$title" />
				<xsl:with-param name="scope" select="$scope" />
			</xsl:call-template>
		</xsl:variable>

		<xsl:if test="not($entry = '')">
		
			<xsl:variable name="orgLabel" select="$entry/entry/label" /> 

			<xsl:comment>SALDA Keyword Organization = <xsl:value-of select="$orgLabel" /></xsl:comment>
			<xsl:variable name="slug">
				<xsl:call-template name="slugify">
					<xsl:with-param name="text" select="$orgLabel" />
				</xsl:call-template>
			</xsl:variable>
	
			<xsl:variable name="concept" select="concat($id, 'concept/organization/moa/', $slug)" />
			<xsl:variable name="organization" select="concat($id, 'organization/moa/', $slug)" />
	
			<xsl:element name="locah:associatedWith">
				<xsl:comment>About the Concept (Organization)</xsl:comment> 
				<xsl:element name="skos:Concept">
					<xsl:attribute name="rdf:about"><xsl:value-of select="$concept" /></xsl:attribute>
		
					<xsl:element name="rdfs:label"><xsl:attribute name="xml:lang" select="'en'" /><xsl:value-of select="$orgLabel"/></xsl:element>
					<xsl:element name="skos:prefLabel"><xsl:attribute name="xml:lang" select="'en'" /><xsl:value-of select="$orgLabel"/></xsl:element>
					
					<xsl:element name="skos:inScheme">
						<xsl:element name="skos:ConceptScheme">
							<xsl:attribute name="rdf:about"><xsl:value-of select="concat($id, 'conceptscheme/moa')"/></xsl:attribute>
							<xsl:element name="rdfs:label"><xsl:attribute name="xml:lang" select="'en'" /><xsl:value-of select="'MOA'"/></xsl:element>
						</xsl:element>
					</xsl:element>
		
					<xsl:element name="foaf:focus">
						<xsl:comment>About the Organization</xsl:comment> 
						<xsl:element name="foaf:Organization">	
							<xsl:attribute name="rdf:about"><xsl:value-of select="$organization" /></xsl:attribute>
							<xsl:element name="rdf:type">
								<xsl:attribute name="rdf:resource"><xsl:value-of select="concat($foaf, 'Agent')" /></xsl:attribute>
							</xsl:element>
							<xsl:element name="rdf:type">
								<xsl:attribute name="rdf:resource"><xsl:value-of select="concat($dcterms, 'Agent')" /></xsl:attribute>
							</xsl:element>
							<xsl:element name="rdfs:label"><xsl:attribute name="xml:lang" select="'en'" /><xsl:value-of select="$orgLabel"/></xsl:element>

							<xsl:for-each select="$entry/entry/sameas">
								<xsl:element name="owl:sameAs">
									<xsl:attribute name="rdf:resource" select="." />
								</xsl:element>
							</xsl:for-each>
							
						</xsl:element>
					</xsl:element>
				</xsl:element>
			</xsl:element>
		</xsl:if>

	</xsl:for-each>
	
	<xsl:for-each select="document($keywords)/keywords/entry[type='Place']">

		<xsl:variable name="entry">
			<xsl:call-template name="test-keyword">
				<xsl:with-param name="entry" select="." />
				<xsl:with-param name="i" select="1" />
				<xsl:with-param name="title" select="$title" />
				<xsl:with-param name="scope" select="$scope" />
			</xsl:call-template>
		</xsl:variable>

		<xsl:if test="not($entry = '')">
		
			<xsl:variable name="placeLabel" select="$entry/entry/label" /> 

			<xsl:comment>SALDA Keyword Place = <xsl:value-of select="$placeLabel" /></xsl:comment>
			<xsl:variable name="slug">
				<xsl:call-template name="slugify">
					<xsl:with-param name="text" select="$placeLabel" />
				</xsl:call-template>
			</xsl:variable>
	
			<xsl:variable name="concept" select="concat($id, 'concept/place/moa/', $slug)" />
			<xsl:variable name="Place" select="concat($id, 'place/moa/', $slug)" />
	
			<xsl:element name="locah:associatedWith">
				<xsl:comment>About the Concept (Place)</xsl:comment> 
				<xsl:element name="skos:Concept">
					<xsl:attribute name="rdf:about"><xsl:value-of select="$concept" /></xsl:attribute>
		
					<xsl:element name="rdfs:label"><xsl:attribute name="xml:lang" select="'en'" /><xsl:value-of select="$placeLabel"/></xsl:element>
					<xsl:element name="skos:prefLabel"><xsl:attribute name="xml:lang" select="'en'" /><xsl:value-of select="$placeLabel"/></xsl:element>
					
					<xsl:element name="skos:inScheme">
						<xsl:element name="skos:ConceptScheme">
							<xsl:attribute name="rdf:about"><xsl:value-of select="concat($id, 'conceptscheme/moa')"/></xsl:attribute>
							<xsl:element name="rdfs:label"><xsl:attribute name="xml:lang" select="'en'" /><xsl:value-of select="'MOA'"/></xsl:element>
						</xsl:element>
					</xsl:element>
		
					<xsl:element name="foaf:focus">
						<xsl:comment>About the Place</xsl:comment> 
						<xsl:element name="wgs84_pos:SpatialThing">	
							<xsl:attribute name="rdf:about"><xsl:value-of select="$Place" /></xsl:attribute>
							<xsl:element name="rdfs:label"><xsl:attribute name="xml:lang" select="'en'" /><xsl:value-of select="$placeLabel"/></xsl:element>

							<xsl:for-each select="$entry/entry/sameas">
								<xsl:element name="owl:sameAs">
									<xsl:attribute name="rdf:resource" select="." />
								</xsl:element>
							</xsl:for-each>
							
						</xsl:element>
					</xsl:element>
				</xsl:element>
			</xsl:element>
		</xsl:if>

	</xsl:for-each>

</xsl:template>


</xsl:stylesheet>

